import { defineNuxtPlugin } from "nuxt/app";
import { BD_PACKAGE_ID, PackageEnum } from "~/config";
import { useGlobalStore } from "~/store/global";

export default defineNuxtPlugin({
  name: "appPackageId-plugin",
  parallel: true,
  async setup() {
    const globalStore = useGlobalStore();
    const router = useRouter();

    // 通过链接判断当前是哪个包,然后进行赋值
    const path = router.currentRoute.value.path;

    if (path.includes(`/${PackageEnum.btcDanaTradingType}/`)) {
      // btcDanaTrading
     globalStore.$patch((state) => {
        if (!state.packageId) state.packageId = PackageEnum.btcDanaTrading;
        // BtcDanaTrading的facebookAppId
        state.facebookAppId = "191378223852418";
        state.googleClientId =
          "795043224873-6es7u74eha49ro3i5fismt9kbmrb9o84.apps.googleusercontent.com";
      });
    } else if (path.includes(`/${PackageEnum.btcDanaInvestType}/`)) {
      // btcDanaInvest
     globalStore.$patch((state) => {
        if (!state.packageId) state.packageId = PackageEnum.btcDanaInvest;
        // BtcDanaInvest的facebookAppId
        state.facebookAppId = "225592606941584";
        state.googleClientId =
          "736732343145-a8d15dv0f52jc2dgt89ns2fh9uv0l0s6.apps.googleusercontent.com";
      });
    } else if (path.includes(`/${PackageEnum.btcDanaEliteType}/`)) {
      // btcDanaElite
     globalStore.$patch((state) => {
        if (!state.packageId) state.packageId = PackageEnum.btcDanaElite;
        // BtcDana的facebookAppId
        state.facebookAppId = "596527947857953";
        state.googleClientId =
          "803913689494-giorienobuqcpkj88obltvtvuj87q7bu.apps.googleusercontent.com";
      });
    } else if (path.includes(`/${PackageEnum.forexDanaTradeType}/`)) {
      // forexDanaTrade
     globalStore.$patch((state) => {
        if (!state.packageId) state.packageId = PackageEnum.forexDanaTrade;
        // ForexDanaTrade的facebookAppId
        state.facebookAppId = "832820474951842";
        state.googleClientId =
          "374832638592-t9611m5l40eog2cf60kcqh5ilcenl949.apps.googleusercontent.com";
      });
    } else if (path.includes(`/${PackageEnum.forexDanaType}/`)) {
      // forexDana
     globalStore.$patch((state) => {
        if (!state.packageId) state.packageId = PackageEnum.forexDana;
        // ForexDana的facebookAppId
        state.facebookAppId = "591342858266100";
        state.googleClientId =
          "687783755571-ujbmva18qoikv367l73jboo4qirgp6dc.apps.googleusercontent.com";
      });
    }
    // Bd Dana
    else if (path.includes(`/${PackageEnum.btcDanaType}/`)) {
     globalStore.$patch((state) => {
        if (!state.packageId) state.packageId = PackageEnum.btcDana;
        state.facebookAppId = "596527947857953"; // 目前跟 iOS 客户端一样
        state.googleClientId =
          "803913689494-sj24t1gg4a1vs0k18nqfkjk47qa9ekeg.apps.googleusercontent.com"; // 目前跟 iOS 客户端一样
      });
    }
    // 默认
    else {
     globalStore.$patch((state) => {
        if (!state.packageId && process.env.NODE_ENV == "development") {
          // 调试模式 dev ，配置默认参数
          state.packageId = PackageEnum.btcDana;
        }
        state.facebookAppId = "596527947857953"; // 默认的facebookAppId
        state.googleClientId =
          "803913689494-giorienobuqcpkj88obltvtvuj87q7bu.apps.googleusercontent.com";
      });
    }
  },
});
